#include <imbus.h>
#include <stdio.h>
#include <string.h>

int compare_char (IMConstPointer a, IMConstPointer b, IMPointer data)
{
    return *((const IMChar*)a) - *((const IMChar*)b);
}

int compare_int (IMConstPointer a, IMConstPointer b, IMPointer data)
{
    return *((const IMInt*)a) - *((const IMInt*)b);
}

int main (int argc, char *argv [])
{
    IMChar str [] = "Hello world.";
    IMInt  dim [] = {5, 6, 3, 1, 2, 10, 9, 8, 6, 4, 2, 11, 10, 7, 7, 3, 3, 12, 0};
    IMInt  i;
    IMChar *pc;
    IMInt  *pi;

    im_init (&argc, &argv);

    im_qsort_with_data (str, strlen (str), 1, compare_char, 0);
    im_qsort_with_data (dim, IM_N_ELEMENTS(dim), sizeof (IMInt), compare_int, 0);

    printf ("%s\n", str);

    pc = im_lower_bound_with_data (str, strlen (str), 1, "o", compare_char, 0);
    printf ("o lower: %s\n", pc);
    pc = im_upper_bound_with_data (str, strlen (str), 1, "o", compare_char, 0);
    printf ("o upper: %s\n", pc);

    pc = im_lower_bound_with_data (str, strlen (str), 1, "w", compare_char, 0);
    printf ("w lower: %s\n", pc);
    pc = im_upper_bound_with_data (str, strlen (str), 1, "w", compare_char, 0);
    printf ("w upper: %s\n", pc);

    for (i = 0; i < IM_N_ELEMENTS(dim); ++i)
        printf ("%d,", dim [i]);
    printf ("\n");

    i = 4;
    pi = im_lower_bound_with_data (dim, IM_N_ELEMENTS(dim), sizeof (IMInt), &i, compare_int, 0);
    printf ("4 lower: %d-%d\n", pi - dim, *pi);
    pi = im_upper_bound_with_data (dim, IM_N_ELEMENTS(dim), sizeof (IMInt), &i, compare_int, 0);
    printf ("4 upper: %d-%d\n", pi - dim, *pi);


    return 0;
}
/*
vi:ts=4:nowrap:ai:expandtab
*/
